package com.shengsheng.expschedule.service.expschedule.controller.admin;


import com.shengsheng.expschedule.base.result.R;
import com.shengsheng.expschedule.service.expschedule.entity.Section;
import com.shengsheng.expschedule.service.expschedule.service.SectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程节次表 前端控制器
 * </p>
 *
 * @author yuan
 * @since 2021-09-30
 */
@RestController
@RequestMapping("/admin/expschedule/section")
@Api(tags = "课程节次管理")
@RefreshScope
public class SectionController {

    @Autowired
    private SectionService sectionService;

    @ApiOperation("添加课程节次")
    @PostMapping("/save")
    public R saveSection(@ApiParam(value = "课程节次对象",required = true)
                         @RequestBody Section section) {
        if (sectionService.save(section)) return R.ok().message("添加成功");
        return R.error().message("添加失败");
    }

    @ApiOperation("根据批次获得课程节次时间")
    @GetMapping("/get/{batchType}")
    public R getSectionByBatchType(@ApiParam(value = "批次类型", required = true)
                                   @PathVariable Integer batchType) {
        List<Section> sectionList = sectionService.getSectionByBatchType(batchType);
        return R.ok()
                .data("items", sectionList)
                .message("获取数据成功");
    }

}

